//================通讯录代码================================
var contactTag=''; // 通讯录tag：  real || notreal

/**
 * 初始化滚动
 */
mui('#pullrefresh1').scroll({
    deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
});

/**
 * 重置
 */
function contactReset(){
    mui('.mui-scroll-wrapper').scroll().scrollTo(0,0,100);//100毫秒滚动到顶
    setTimeout(()=>{
        var $table = document.body.querySelector('#pullrefresh1 .mui-table-view');
        $table.innerHTML = '';
        loadContact()
    },500)

}

/**
 *  加载通讯录
 */
function  loadContact() {
    var $table = document.body.querySelector('#pullrefresh1 .mui-table-view');
    setTimeout(()=>{
        for(var i=0;i<10;i++){
            var li = document.createElement('li');
            li.className = 'mui-table-view-cell mct';
            li.innerHTML = `<div class="mui-row">
                        <div class="mui-col-xs-9 detail_btn">
                            <div class="mui-row">
                                <div class="mui-col-xs-7 mct__name">陈鹏 V1</div>
                                <!--<div class="mui-col-xs-5 mct_count">用户数:0(0)</div>-->
                            </div>
                            <div class="mct__phone">13032323321</div>
                            <div class="mct__date">注册时间：2019-07-15</div>
                        </div>
                        <div class="mui-col-xs-3 mui-navigate-right">
                            <div class="call"  title="13032323321">
                                <i class="fa fa-phone"></i>
                            </div>
                        </div>
                    </div>`;
            $table.appendChild(li)
            bindContactClick();
        }
    },500);
}

/**
 * 事件绑定
 */
function bindContactClick(){
    // 查看详情
    mui(".mui-row").on('tap','.detail_btn',function () {
        // 返回按钮
        mui("#backBtn")[0].style.display = 'none';
        mui("#prevBtn2")[0].style.display = 'block';
        // 通讯录
        mui("#segmentedControlbox")[0].style.display = 'none';
        mui(".filter")[0].style.display = 'none';
        mui("#pullrefresh1")[0].style.display = 'none';
        // 详情
        mui("#detail")[0].style.display = 'block';
    });
    // 打电话
    mui('.mui-col-xs-3').on('tap',".call",function () {
        var phone = this.getAttribute('title');
        window.location.href = 'tel:'+phone
    })

}

mui.ready(function () {
    // 加载通讯录
    loadContact();

    // 通讯录切换
    mui("#segmentedControl").on("tap","a",function () {
        var tagIndex = this.getAttribute('tag'); // day || month
        console.log('tabs',tagIndex)
        contactTag = tagIndex;
        // 重置
        contactReset();
    })

    // 详情 返回 列表
    mui(".mui-bar").on('tap','#prevBtn2',function () {
        // 返回按钮
        mui("#backBtn")[0].style.display = 'block';
        mui("#prevBtn2")[0].style.display = 'none';

        // 详情
        mui("#detail")[0].style.display = 'none';

        // 通讯录
        mui("#segmentedControlbox")[0].style.display = 'block';
        mui(".filter")[0].style.display = 'block';
        mui("#pullrefresh1")[0].style.display = 'block';
    })

})
